<!--
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 * No deletion without permission, or be held responsible to law.
 * @author FIRE
-->
<template>
  <BasicDrawer
    v-bind="$attrs"
    :showFooter="true"
    @register="registerDrawer"
    @ok="handleSubmit"
    width="50%"
  >
    <template #title>
      <Icon :icon="getTitle.icon" size="30" />
      <span class="text-2xl"> 确认图纸信息 </span>
    </template>
    <div class="ml-5">
      <div class="text-2xl">
        {{ record.rsMsg }}
      </div>
      <a-divider />
      <div v-for="(item, index) in record.list" :key="index">
        <div class="m-3 text-xl">
          <span v-if="item.checkResult" class="m-4">
            <Icon icon="i-ant-design:check-circle-filled" color="green" size="30" />
          </span>
          <span v-else class="m-4">
            <Icon icon="i-ant-design:close-circle-outlined" color="red" size="30" />
          </span>
          <span class="text-xl font-bold">{{ index + 1 }}、{{ item.picName }}</span>
        </div>
        <div v-if="item.checkResult" class="m-8 text-xl">
          <div class="p-3">图纸数量：{{ item.orderPic.iqty }}</div>
          <div class="p-3">剩余发出数：{{ item.orderPicFlow.syWxOutQty }} </div>
        </div>
        <div v-if="!item.checkResult" class="m-8 text-xl">
          <div class="p-3">{{ item.errorMsg }}</div>
        </div>
        <a-divider />
      </div>
    </div>
    <!-- 发料 -->
    <wxOut @register="registerOpenOutDrawer" @successPrint="handleSuccess1" />
  </BasicDrawer>
</template>
<script lang="ts">
  export default defineComponent({
    name: 'ViewsM8RdRd01M8Rd01FormXzdd',
  });
</script>
<script lang="ts" setup>
  import { defineComponent, ref, computed, onMounted } from 'vue';
  import { useI18n } from '/@/hooks/web/useI18n';
  import { useMessage } from '/@/hooks/web/useMessage';
  import { router } from '/@/router';
  import { Icon } from '/@/components/Icon';
  import { BasicForm, FormSchema, useForm } from '/@/components/Form';
  import { BasicDrawer, useDrawerInner,useDrawer } from '/@/components/Drawer';
  import { m8Rd01ScanPicAddRow } from '/@/api/m8/rd/rd01/m8Rd01';
  import wxOut from '/@/views/m8/order/flow/wx/m8OrderFlowWxOut/form.vue';
import { error } from 'console';

  const emit = defineEmits(['success', 'register']);

  const { t } = useI18n('setting.pricemodel.wecharPriceModelInv');
  const { showMessage } = useMessage();
  const record = ref<WecharPriceModelUse>({} as WecharPriceModelUse);
  const getTitle = computed(() => ({
    icon: 'i-ant-design:question-circle',
  }));
  let groupedMap = ref({});

  // 发料
  const [registerOpenOutDrawer, { openDrawer: openDrawerOut }] = useDrawer();

  const [registerDrawer, { setDrawerProps, closeDrawer }] = useDrawerInner(async (res) => {
    setDrawerProps({ loading: true });
    record.value = res
    // let data = res.data
    // for (const key in data) {
    //   if (data[key].length) {
    //     data[key].list = [data[key][0]];
    //   } else {
    //     data[key].list = [];
    //   }
    // }
    // groupedMap.value = data;
    record.value.__t = new Date().getTime();
    setDrawerProps({ loading: false });
  });

  async function handleSubmit() {
    let newArr =  record.value.list.filter(item=>{
      return item.checkResult
    })
    let arr =  newArr.map(item=>{
      return item.orderPicFlow.id;
    })

    if(!arr.length){
      showMessage(t('请至少扫描成功一条图纸！'));
      return false
    }
    
    openDrawerOut(true, {
      selIds: arr.join(','),
      'outUser.userCode': record.value.user.userCode,
    });
    setTimeout(closeDrawer);
    emit('success', arr);
   
  }
</script>
